<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <!-- Your app title -->
  <title>Mocks</title>
  <link rel="stylesheet" href="/css/index.css">
</head>
<body>
<div id="app">
  <div class="div-imput">
    <span class="span">服务器地址</span>
    <input type="text" class="input" id="base" placeholder="示例：http://aw.jnaw.top/aw"
           oninput="baseUpdate()">
  </div>
  <div class="div-imput">
    <span class="span">请求次数&nbsp;&nbsp;&nbsp;</span>
    <input type="number" class="input" id="number" value="1"
           oninput="numberUpdate()">
  </div>

  <!--<div class="div-imput margin-top-15">
    <span class="span">用户名</span>
    <input type="text" class="input" id="username">
  </div>
  <div class="div-imput">
    <span class="span">密码&nbsp;&nbsp;&nbsp;</span>
    <input type="password" class="input" id="password">
    <button type="button" class="button" onclick="login()">登录</button>
    <button type="button" class="button" onclick="test1()">请求</button>
  </div>-->

  <div class="list">
    <% for (var i = 0; i < data.length; i++) { %>
    <a href=".<%= data[i] %>/raw" target="_blank"><%= data[i] %></a><br/>
    <% } %>
  </div>

</div>
<!-- Path to Framework7 Library JS-->
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="/js/utils.js"></script>
<script>
  $(function () {
    var base = localStorage.getItem('baseURL');
    if (base) {
      $('#base').val(base);
    }
    var number = localStorage.getItem('number');
    if (number) {
      $('#number').val(number);
    }
    var username = localStorage.getItem('mock-username');
    if (username) {
      $('#username').val(username);
    }
    var password = localStorage.getItem('mock-password');
    if (password) {
      $('#password').val(password);
    }
  });
  function login() {
    var base = $('#base').val().trim();
    var username = $('#username').val().trim();
    var password = $('#password').val().trim();
    if (!base) {
      alert('服务器地址不能为空');
      return false;
    }
    if (!username) {
      alert('用户名不能为空');
      return false;
    }
    if (!password) {
      alert('密码不能为空');
      return false;
    }
    localStorage.setItem('mock-username', username)
    localStorage.setItem('mock-password', password)
    axiosFun('/login', 'POST', {
      base: base,
      api: '/user/login',
      username: username,
      password: password,
    }, function (res) {
      var data = res.data || {}
      if (data.result == 0) {
        alert('登录成功')
      } else if (data.result == 2 || data.result == 7) {
        alert('用户名或密码错误')
      } else {
        alert('登录失败')
      }
    });
  }
  function test1() {
    axiosFun('/post', 'POST', {
      base: 'http://oa.jnaw.top/oa',
      api: '/journal/list',
      number: 1,
    }, function (res) {
      var data = res.data || {}
    });
  }
</script>
</body>
</html>